package tt.dz.dao.ext.system;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Repository;
import tt.dz.dao.base.OmsCommonDao;
import tt.dz.entity.exception.OmsDaoException;
import tt.dz.entity.system.OmsOperationSpList;

/**
 * 充电运营服务商 数据操作dao
 * @author huangaho
 * @date 2015年1月6日
 */
//@Table(name = "oms_operation_sp_list")
@Repository
public class OmsOperationSpListDao extends OmsCommonDao<OmsOperationSpList> 
{
	
	public String findMaxSequence() throws OmsDaoException
	{
		String sql = "select max(right(oper_merchant_id,3)) as maxId from oms_operation_sp_list";
		try
		{
			return (String)this.getJdbcTemplate().queryForObject(sql, String.class);
		}
		catch(Exception e)
		{
			logError(e.getMessage(), e);
			throw new OmsDaoException(e);
		}
	}
	
//	
	
	public Integer findUserIsSpuer(String operId)
	{
		String sql = "select ifnull(super_flag,0) as super_flag from oms_operation_sp_list where oper_merchant_id = (select ol.entity_id from oms_oper_list ol where ol.oper_id = ? and entity_type = 1 )";
		try
		{
			Object[] args = {operId};
			return this.getJdbcTemplate().queryForInt(sql, args);
		}
		catch(EmptyResultDataAccessException e)
		{
			return 0;
		}
		catch(Exception e)
		{
			logError(e.getMessage(), e);
			return 0;
		}
	}
	
}
